import { v4 as uuidv4 } from 'uuid';

import { Seeder } from '../../umzug';
import { seedUsers } from './20211003182031-sample-user';

/**
 * 这里是将 mergeUserQuestionnaire 与 user 的 id 相同
 */
const seedMergeUserAndQuestionnaire = seedUsers.map((user) => {
  const { id } = user;

  return {
    id,
    uuid: uuidv4(),
    fk_user: id,
    fk_questionnaire: 1,
    start_time: Number(new Date()),
    end_time: Number(new Date()) + 1000,
    complate_flag: 0,
    created_at: new Date(),
    updated_at: new Date()
  };
});

export const up: Seeder = async ({ context: sequelize }) => {
  await sequelize
    .getQueryInterface()
    .bulkInsert('merge_user_questionnaire', seedMergeUserAndQuestionnaire);
};

export const down: Seeder = async ({ context: sequelize }) => {
  await sequelize.getQueryInterface().bulkDelete('merge_user_questionnaire',
    { id: seedMergeUserAndQuestionnaire.map((u) => u.id) });
};
